﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;

namespace SharePointCommander.Model.TreeView
{
    public class SCService : SCTreeViewItem<SPService>
    {
        public SCService(SCTreeViewItem parent, SPService service)
            : base(parent, service)
        {
            Header = service.TypeName;

            Expanded += new System.Windows.RoutedEventHandler(SCService_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCService_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!ItemsSource.OfType<SCProperties>().Any())
            {
                ItemsSource = new[] { 
#if SP2010
                    new SCServiceApplicationCollection(this, SPObject.Applications) as TreeViewItem,
#endif
                    new SCTreeViewItem<SPJobDefinitionCollection>(this, SPObject.JobDefinitions) {
                        Header = "Job Definitions"
                    },
                    new SCProperties(this, SPObject.Properties) as TreeViewItem, 
                    new SCServiceInstanceDependencyCollection(this, SPObject.Instances) as TreeViewItem
                };
            }
        }
    }
}
